package com.viphuli.app.tool.fragment;

import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.OnClick;

import com.loopj.android.http.RequestParams;
import com.offroader.utils.StringUtils;
import com.offroader.utils.ViewUtils;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.http.ApiRequest;

public abstract class AccountVCodeFragment extends BaseProgressFragment{
	
	@Bind(R.id.id_account_login_phone_text)
	protected EditText phoneText;

	@Bind(R.id.id_account_login_vcode_btn)
	protected TextView vcodeBtn;

	@Bind(R.id.id_account_login_vcode_text)
	protected EditText vcodeText;
	
	//是否正在倒计时
	private boolean isCountDown = false;
	
	
	@OnClick(R.id.id_account_login_vcode_btn)
	public void getVCode() {
		String phone = phoneText.getText().toString();

		if (StringUtils.isBlank(phone)) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_phone_number), Toast.LENGTH_SHORT).show();
			return;
		}

		if (isCountDown) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_count_down), Toast.LENGTH_SHORT).show();
			return;
		}

		RequestParams params = new RequestParams();
		params.put("phone_number", phone);

		ApiRequest.accountLoginVcode.request(this, params);

	}
	
	@OnClick(R.id.id_account_login_vcode_voice)
	public void vCodeVoice() {

		if (StringUtils.isBlank(phoneText.getText().toString())) {
			ViewUtils.toast(R.string.tip_input_phone_number);
			return;
		}

		RequestParams params = new RequestParams();
		params.put("phone_number", phoneText.getText().toString());
		ApiRequest.accountLoginVcodeVoice.request(this, params);
	}
	
	public void setCountDown(boolean isCountDown) {
		this.isCountDown = isCountDown;
	}
	
	public TextView getPhoneText() {
		return phoneText;
	}

	public TextView getVcodeBtn() {
		return vcodeBtn;
	}

	public TextView getVcodeText() {
		return vcodeText;
	}

}
